﻿#ifndef SERVER_H
#define SERVER_H

#include <QTcpServer>
#include <QObject>
#include "DispatcherThread.h"
class Server : public QTcpServer
{
    Q_OBJECT
public:
    Server(QObject *parent = 0,int port = 0);

    static Server * instance();
    static Server * getInstance();






signals:
    void updateMsg(QString, QString);

    void updateMsg(QJsonObject&);


    void updateClient(QString);

    void removeClient(QString);

    void disMsg(QString,QString);

    void writeMsg(int,QJsonObject);

public slots:

    void updateMessage(QString ip_port,QString msg);

    void updateMessage(QJsonObject json);

    void deleteClientThread(DispatcherThread*);

    void updateClients(QString);
    void writeMsgToClient(int socketDescriptor,QJsonObject json);

    void returnDatatoDistach(int socketDescriptor, QJsonObject json);


protected:
    void incomingConnection(qintptr socketDescriptor);
private:
    static Server *m_instance;
    QList<DispatcherThread*> m_threadList;

};

#endif // SERVER_H
